package com.wang.tool.task;


import com.alibaba.fastjson.JSON;

import java.io.Serializable;
import java.util.List;

/**
 * @Description 任务基础
 * @Author shaopeng
 * @Date 2023/6/3
 * @Version 1.0
 */
public class TaskBase implements Serializable {

    private static final long serialVersionUID = -7049852722546270284L;


    /**
     * 名称
     */
    private String taskName;

    /**
     * 处理器
     */
    private String handler;


    /**
     * 关联的id
     * 多个,分割
     * 此task完成后可以自检relateIds的任务
     * 使用逻辑很像父子关系，但是应该认为是铁索连船，而非父子
     */
    private List<Long> relateIds;

    /**
     * 业务id
     * 假如是文档切割任务，那么这里就可以存储文档id，框架不用，任务自用属性
     */
    private String ownerId;


    public static TaskBase build(String taskName, String handler) {
        TaskBase task = new TaskBase();
        task.setTaskName(taskName);
        task.setHandler(handler);
        return task;
    }

    public static TaskBase build(String taskName, Class<?> handlerType) {
        return build(taskName, handlerType.getSimpleName());
    }


    public TaskBase ownerId(String ownerId) {
        this.ownerId = ownerId;
        return this;
    }

    public TaskBase relateIds(List<Long> relateIds) {
        this.relateIds = relateIds;
        return this;
    }


    public String getOwnerId() {
        return ownerId;
    }

    public void setOwnerId(String ownerId) {
        this.ownerId = ownerId;
    }

    public List<Long> getRelateIds() {
        return relateIds;
    }

    public void setRelateIds(List<Long> relateIds) {
        this.relateIds = relateIds;
    }

    public String getTaskName() {
        return taskName;
    }

    public void setTaskName(String taskName) {
        this.taskName = taskName;
    }

    public String getHandler() {
        return handler;
    }

    public void setHandler(String handler) {
        this.handler = handler;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
